﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PortalLogReport.Models;
using PortalLogReport.Repositories;
using PortalLogReport.Common;

namespace PortalLogReport.Services
{
    public class ResultService : IResultService
    {
        private IResultRepository _resultRepository;

        #region Service Methods

        public void CreateRepository(string dimensionType, KeyValuePair<string, string> subDimensionType, string intervalType)
        {
            ChartCommon.DimensionTypes dimension = (ChartCommon.DimensionTypes)Enum.Parse(typeof(ChartCommon.DimensionTypes), dimensionType);

            //switch (dimension)
            //{
            //    case ChartCommon.DimensionTypes.Category:
            //        _resultRepository = new CategoryRepository(subDimensionType);
            //        break;
            //    case ChartCommon.DimensionTypes.Error:
            //        _resultRepository = new ErrorRepository(subDimensionType);
            //        break;
            //    default:
            //        _resultRepository = new CategoryRepository(subDimensionType);
            //        break;
            //}

            switch (dimension)
            {
                case ChartCommon.DimensionTypes.Category:
                    _resultRepository = new LevelRepository("appdomainname", subDimensionType.Key);
                    break;
                case ChartCommon.DimensionTypes.Error:
                    _resultRepository = new LevelRepository("message", subDimensionType.Key);
                    break;
                default:
                    _resultRepository = new CategoryRepository(subDimensionType);
                    break;
            }

            _resultRepository.IntervalType = (ChartCommon.Interval)Enum.Parse(typeof(ChartCommon.Interval), intervalType);
        }

        public IList<BaseChartModel> GetResults(DateTime startDate, DateTime endDate)
        {
            return _resultRepository.GetResults(startDate, endDate);
        }

        public BaseChartModel GetResult(DateTime startDate, DateTime endDate)
        {
            return _resultRepository.GetResult(startDate, endDate);
        }

        #endregion
    }
}
